import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/home', },
    {
      path: '/home',
      name: 'home',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: HomeView,
      children:[
        { path: '/test', name: 'test',component: () => import('../views/Test.vue') },
        { path: '/notes/notesRouter', name: 'notesRouter',component: () => import('../notes/NotesRouter.vue') },
        { path: '/notes/notesError', name: 'notesError',component: () => import('../notes/NotesError.vue') },
        { path: '/notes/notesSetup', name: 'notesSetup',component: () => import('../notes/NotesSetup.vue') },
        { path: '/notes/notesRef', name: 'notesRef',component: () => import('../notes/NotesRef.vue') },
        { path: '/notes/notesParentChild', name: 'notesParentChild',component: () => import('../notes/NotesParentChild.vue') },
        { path: '/notes/notesVuex', name: 'notesVuex',component: () => import('../notes/NotesVuex.vue') },
        { path: '/notes/notesAxios', name: 'notesAxios',component: () => import('../notes/NotesAxios.vue') },
        { path: '/notes/notesAsync', name: 'notesAsync',component: () => import('../notes/NotesAsync.vue') },
        { path: '/form/cardView', name: 'cardView',component: () => import('../views/form/CardView.vue') },
        { path: '/form/codeChunkView', name: 'codeChunkView',component: () => import('../views/form/CodeChunkView.vue') },
      ]
    },

  ]
})
router.beforeEach((to,from,next)=>{
  if(to.name == ''){
    next()
  }else{
    // token验证
    // if('token'){
    //   Message('登录过期，请重新登录')
    //   router.replace({
    //     path:'/login'
    //   })
    // }else{

    // }
    next()
  }
})
router.afterEach((to,from)=>{
  console.log('from:' + from.name + ' , to:' + to.name )
})

export default router
